<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%--
  Created by IntelliJ IDEA.
  User: Tiler
  Date: 2020/11/5
  Time: 10:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript">
        function delBooks() {
            $("#book-form").submit();
        }
    </script>
</head>
<body>
<h1 class="text-center pt-3 pb-3">图书管理后台</h1>

<div class="container">
    <div class="offset-md-1 col-md-10">
        <div class="row pl-2">
            <form class="form-inline">
                <div class="form-group">
                    <button type="button" onclick="window.open('/goto_add_book')" class="btn btn-link btn-sm">
                        增加记录
                    </button>
                    <button type="button" onclick="delBooks()" class="btn btn-sm btn-link">
                        批量删除
                    </button>
                </div>
            </form>
        </div>

        <form id="book-form" action="/del_books" method="post">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>选项</th>
                    <th>编号</th>
                    <th>名称</th>
                    <th>出版社</th>
                    <th>分类</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${bookPage.bookList}" var="b">
                    <tr>
                        <td class="text-right">
                            <input type="checkbox" class="form-check-input" name="bookId" value="${b.bookId}">
                        </td>
                        <td>${b.bookId}</td>
                        <td>${b.bookName}</td>
                        <td>${b.publisherName}</td>
                        <td>
                            <c:forEach items="${b.categories}" var="c">
                                ${c.categoryName}<br>
                            </c:forEach>
                        </td>
                        <td>
                            <a href="/goto_set_book?id=${b.bookId}" target="_blank">修改</a>
                            <a href="/goto_set_book?id=${b.bookId}" target="_blank">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </form>

        <nav class="pb-5 pt-3">
            <ul class="pagination justify-content-center">
                <c:if test="${bookPage.pageNum == 1}">
                    <li class="page-item disabled"><a class="page-link" href="#">首页</a></li>
                </c:if>
                <c:if test="${bookPage.pageNum > 1}">
                    <li class="page-item"><a class="page-link" href="/all_books?page=1&size=${bookPage.pageSize}">首页</a></li>
                </c:if>

                <c:forEach begin="1" end="${bookPage.pageCount}" var="i">
                    <c:if test="${bookPage.pageNum == i}">
                        <li class="page-item active"><a class="page-link" href="#">${i}</a></li>
                    </c:if>
                    <c:if test="${bookPage.pageNum != i}">
                        <li class="page-item"><a class="page-link" href="/all_books?page=${i}&size=${bookPage.pageSize}">${i}</a></li>
                    </c:if>
                </c:forEach>

                <c:if test="${bookPage.pageNum == bookPage.pageCount}">
                    <li class="page-item disabled"><a class="page-link" href="#">末页</a></li>
                </c:if>
                <c:if test="${bookPage.pageNum < bookPage.pageCount}">
                    <li class="page-item"><a class="page-link" href="/all_books?page=${bookPage.pageCount}&size=${bookPage.pageSize}">末页</a></li>
                </c:if>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>
